Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump min go version to 1.18 && read build info from embedded binary #2548

Merged
merged 6 commits into from
Jul 18, 2022

Conversation

dprotaso
Copy link
Member

Fixes: #2427

This should let us drop HEAD and refs in our kodata folders

/kind cleanup

Release Note

changeset.Get now reads from vcs information embedded by the golang compiler

@knative-prow knative-prow bot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Jul 16, 2022
@dprotaso
Copy link
Member Author

cc @wlynch

@codecov
Copy link

codecov bot commented Jul 16, 2022

Codecov Report

Merging #2548 (512c6b4) into main (418e138) will decrease coverage by 0.02%.
The diff coverage is 97.36%.

@@            Coverage Diff             @@
##             main    #2548      +/-   ##
==========================================
- Coverage   81.64%   81.61%   -0.03%     
==========================================
  Files         163      163              
  Lines        9745     9715      -30     
==========================================
- Hits         7956     7929      -27     
+ Misses       1551     1549       -2     
+ Partials      238      237       -1     
Impacted Files Coverage Δ
logging/config.go 81.25% <75.00%> (ø)
apis/contexts.go 100.00% <100.00%> (ø)
changeset/commit.go 100.00% <100.00%> (+4.83%) ⬆️
...k/resourcesemantics/validation/validation_admit.go 93.12% <100.00%> (+0.05%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f1f36a2...512c6b4. Read the comment docs.

@dprotaso
Copy link
Member Author

unit tests flaked (metrics)

cc @imjasonh for tekton pipeline downstream failure -

@dprotaso
Copy link
Member Author

dprotaso commented Jul 16, 2022

One option is we fail silently if the vcs.revision is missing - which would happen in go test scenarios or go run somefile.go

@imjasonh
Copy link
Member

One option is we fail silently if the vcs.revision is missing - which would happen in go test scenarios or go run somefile.go

Or if the binaries/images are built with -buildvcs=false, which some downstream might want to do if, e.g., Git isn't available in the CI environment, or they want to omit source information for some other reason.

I'll prepare a PR to fix Tekton's usage though, it doesn't look like these tests need to use changeset.Get anyway.

imjasonh added a commit to imjasonh/pipeline that referenced this pull request Jul 16, 2022
knative/pkg#2548 changes pkg/changeset.Get to
read VCS information from information embedded by the Go compiler into
built binaries, instead of relying on the convention that a kodata/HEAD
symlink exists pointing to the repo's .git/HEAD, and a kodata/refs
points to .git/refs.

This fails in tests though, since tests don't stamp this information
into the binary where it can be read.

This change removes our tests' usage of changeset.Get and instead
replaces those fake commit SHAs with more obviously placeholder values.
It doesn't seem that the tests cared that it was an actual SHA, let
along the actual current SHA, they just needed any value that looked
like a SHA.
- Use a sync.Once to prevent double parsing
- Support SHA256
- Allow non-SHA revision strings
@dprotaso
Copy link
Member Author

dprotaso commented Jul 16, 2022

Ok added some tweaks

  • Use a sync.Once to prevent double parsing
  • Support SHA256 (git)
  • Allow non-SHA revision strings (ie. support SVN or whatever)

koDataPath := os.Getenv(koDataPathEnvName)
if koDataPath == "" {
return nil, fmt.Errorf("%q does not exist or is empty", koDataPathEnvName)
if shaRegexp.MatchString(revision) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, we don't need this check 😎

(not necessarily advice to remove it, just a funny coincidence)

Actually, I wonder if this should just be if len(revision) >= 7, so folks using Subversion or whatever can still enjoy this goodness. I'm not sure there aren't other places we assume Git in and around here, but just in case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd leave it as - since I don't want to assume truncating will work for different VCS - ie svn is numeric so we'd be alternating the commit id

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A further improvement could be to do this only for vcs that use SHA's for revisions -ie git, hg etc.

@knative-prow knative-prow bot added the lgtm Indicates that a PR is ready to be merged. label Jul 18, 2022
@knative-prow knative-prow bot merged commit 473ba31 into knative:main Jul 18, 2022
@knative-prow
Copy link

knative-prow bot commented Jul 18, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dprotaso, imjasonh

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@dprotaso dprotaso deleted the changeset-runtime branch July 18, 2022 15:00
// Get returns the 'vcs.revision' property from the embedded build information
// This function will return an error if value is not a valid Git SHA
//
// The result will have a '-dirty' suffix if the workspace was not clean
func Get() (string, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a changeset.MustGet that panics if it can't detect the version? I'm updating some callsites to get this once at init-time, and they're all just log.Fataling if this returns an error. Or should this return Unknown if it can't read build info, and just never return an error?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or should this return Unknown if it can't read build info, and just never return an error?

I was thinking about this - let me do it in a follow up

dprotaso added a commit to dprotaso/serving that referenced this pull request Jul 18, 2022
build info (vcs.revision) is now embedded in the go binary with go1.18

see: knative/pkg#2548
knative-prow bot pushed a commit to knative/serving that referenced this pull request Jul 18, 2022
build info (vcs.revision) is now embedded in the go binary with go1.18

see: knative/pkg#2548
tekton-robot pushed a commit to tektoncd/pipeline that referenced this pull request Jul 21, 2022
knative/pkg#2548 changes pkg/changeset.Get to
read VCS information from information embedded by the Go compiler into
built binaries, instead of relying on the convention that a kodata/HEAD
symlink exists pointing to the repo's .git/HEAD, and a kodata/refs
points to .git/refs.

This fails in tests though, since tests don't stamp this information
into the binary where it can be read.

This change removes our tests' usage of changeset.Get and instead
replaces those fake commit SHAs with more obviously placeholder values.
It doesn't seem that the tests cared that it was an actual SHA, let
along the actual current SHA, they just needed any value that looked
like a SHA.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use runtime/debug in our changeset package
2 participants